package  com.zzkj.util
{
	import com.zzkj.vo.query.FieldVO;
	import com.zzkj.vo.query.QueryInfoVO;
	
	public class QueryBuilder
	{
		public function QueryBuilder()
		{
		}
		
		public static function createQuery(entityName:String,fields:Array):QueryInfoVO{
				var q:QueryInfoVO = new QueryInfoVO();
				q.entityAlias = null;
				q.listType = QueryInfoVO.LISTTYPE_LIST;
				q.conjunctionType = QueryInfoVO.CONJUNCTIONTYPE_AND;
				q.queryObjectName = entityName;
				q.fields = createQueryFields(fields);
				return q;
			}
		private static function createQueryFields(fields:Array):Array{
				var fieldList:Array = new Array();
				if(fields!=null){
					var len:Number = fields.length;
					for(var i:Number=0;i<len;i++){
						var obj:Object = fields[i];
						var field:FieldVO = new FieldVO();
						field.condition = QueryInfoVO.CONDITION_LIKE_END_IC;
						field.fieldName = obj.name;
						field.fieldValue = obj.value;
						if(obj.fromAO!=null){
							field.fromAssociateObject = obj.fromAO;
						}
						if(obj.fullCode!=null){
							field.fieldName = obj.fullCode;
						}
						if(field.fieldValue!=null && field.fieldValue!=' '&&field.fieldValue!='' ){
							fieldList.push(field);
						}
					}				
				}
				return fieldList;
			}

	}
}